/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class MarblesRegroupingHard {
public:
    int minMoves(vector <string> boxes);
};
int nbox;
int ncol;
inline int toI(string str) {
    int d;
    sscanf(str.c_str(),"%d",&d);
    return d;
}

inline vector<int> toVI(string str) {
    stringstream ss(str);
    vector<int> vi;
    for (string tmp=""; getline(ss,tmp,' '); ) {
        if ( LN(tmp)<1 )continue;
        vi.pb( toI(tmp) );
    }
    return vi;
}
int G[51][15];
inline int f(int boxid,int colorid) {
    int dd=0;
    for (int i=0;i<nbox;++i) {
        if ( i!=boxid ) {
            dd+=( G[i][colorid] );
        }
    }
    return dd;
}
int dp[(1<<14)+1][51];

int go(int id, int msk) {
    if (id==nbox) {
        if ( __builtin_popcount(msk)==ncol ) {
            return 0;
        }
        return (int)1023456789;
    }
    if ( dp[msk][id]!=-1 ) {
        return dp[msk][id];
    }
    int best = (int)1023456789;
    // current box a kono color na niye
    int a = go(id+1,msk);
    best = min( best, a );
    // current box a kono akta color niye
    for (int i=0;i<ncol;++i) {
        if ( (msk&(1<<i))==0 ) {
            int b = f(id,i)+go(id+1, (msk|(1<<i)) );
            best = min( best, b );
        }
    }
    return dp[msk][id]=best;
}

int MarblesRegroupingHard :: minMoves(vector <string> boxes) {
    int retval=(int)1023456789;
    nbox = SZ( boxes );
    ncol = -1;

    fo(i,nbox) {
        vector<int> vi = toVI( boxes[i] );
        if ( ncol==-1 ) {
            ncol = SZ(vi);
        }
        fo(j,ncol) {
            G[i][j] = vi[j];
        }
    }
    SET(dp,-1);
    retval = go(0,0);
    return retval;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, bool hasAnswer, int p1) {
    cout << "Test " << testNum << ": [" << "{";
    for (int i = 0; int(p0.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p0[i] << "\"";
    }
    cout << "}";
    cout << "]" << endl;
    MarblesRegroupingHard *obj;
    int answer;
    obj = new MarblesRegroupingHard();
    clock_t startTime = clock();
    answer = obj->minMoves(p0);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p1 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == p1;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    vector <string> p0;
    int p1;

    {
        // ----- test 0 -----
        string t0[] = {"0"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 0;
        all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        string t0[] = {"77 97","8 0"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 77;
        all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        string t0[] = {"6 97 7","73 45 0","67 45 63"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 170;
        all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        string t0[] = {"97 94 0 99","1 72 46 45","0 10 47 75","0 92 76 20","2 25 98 22"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 559;
        all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
        // ------------------
    }

    {
        // ----- test 4 -----
        string t0[] = {"38 0 0 45 77 61 0 0 8 87 65 53 0 2","0 97 79 37 70 0 69 35 95 11 75 96 77 29","39 32 0 24 63 22 91 71 0 63 92 59 12 0","34 0 0 71 88 13 60 56 0 22 29 89 81 53","69 95 65 0 94 98 84 37 0 87 16 0 58 18","82 0 36 88 0 54 82 40 6 0 34 44 80 2","33 58 7 95 83 87 0 0 79 35 0 51 22 84","7 0 30 57 33 4 0 26 44 55 67 31 88 42","62 58 62 93 91 0 1 0 44 23 95 0 55 57","35 8 22 26 76 0 78 54 0 46 42 0 0 64","93 54 58 0 89 89 0 0 57 0 98 3 24 0","9 0 0 23 82 18 0 46 0 0 94 84 19 18","78 12 6 45 0 80 16 69 59 76 35 0 66 0","0 68 77 13 15 0 52 72 0 0 18 65 23 0","0 0 73 53 0 95 91 44 27 96 85 0 99 85","93 29 4 89 27 44 27 17 21 6 0 8 3 91","0 46 73 94 60 59 15 50 18 75 74 88 46 93","0 0 0 94 93 26 21 83 54 62 0 89 59 77","32 98 0 44 34 38 56 20 0 61 29 94 52 57","52 60 0 22 0 5 38 0 50 98 12 75 0 81","23 0 41 18 36 87 49 32 62 43 22 74 0 97","0 0 30 79 16 73 61 0 75 51 64 13 45 0","11 0 14 2 0 1 2 16 84 37 95 45 48 33","10 0 0 35 0 85 28 76 99 74 76 32 52 8","60 0 96 0 95 26 59 13 0 0 44 42 97 48","3"
                       "4 7 77 25 91 85 35 78 32 99 7 29 18 15","61 50 43 22 42 63 64 50 9 94 42 22 21 33","58 0 41 10 16 0 27 67 83 27 14 37 98 47","37 60 60 76 71 2 84 32 27 39 82 84 0 94","15 98 69 82 36 66 0 97 62 39 0 65 62 67","0 41 0 43 0 0 94 0 0 58 0 0 27 33","53 90 71 91 85 0 32 86 40 60 11 0 99 28","79 62 0 0 79 0 14 62 87 76 35 0 70 0","0 40 73 48 0 63 0 0 63 5 30 18 47 51","75 6 58 69 33 57 66 0 12 0 46 0 65 10"
                      };
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        p1 = 18618;
        all_right = KawigiEdit_RunTest(4, p0, true, p1) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 
